package com.winteam.View;

import com.winteam.Bean.R;
import com.winteam.Controler.Select;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

public class YYCX extends JFrame {

	private JPanel contentPane;
	private JTextField alltext,starttext,livetext;
		Select select = new Select();
	private Vector<String> header =new Vector<>();
	public static void main(String[] args) {
		new YYCX().setVisible(true);
	}


	DefaultTableModel allModel ,startModel,liveModel;

	/**
	 * Create the frame.
	 */
	public YYCX() {
		setTitle("营业查询");
		header.add("房间号");
		header.add("房间类型");
		header.add("单价");
		header.add("用户姓名");
		header.add("用户电话");
		header.add("入住时间");

		setDefaultCloseOperation(1);
		setSize(900,600);
		contentPane = new JPanel();
		this.setLocationRelativeTo(null);
		contentPane.setLayout(null);
		setContentPane(contentPane);
		
		JTabbedPane tabbedPane = new JTabbedPane();
		tabbedPane.setBackground(new Color(184,173,151));
		tabbedPane.setBounds(0, 0, 882, 553);
		contentPane.add(tabbedPane);
		
		JPanel all = new JPanel();
		all.setToolTipText("全部宾客信息查询");
		all.setLayout(null);
			
		tabbedPane.addTab("全部宾客信息查询",  all);
		
		JLabel lblNewLabel = new JLabel("姓名/房间号:");
		lblNewLabel.setBounds(140, 13, 179, 23);
		all.add(lblNewLabel);
		
		alltext = new JTextField();
		alltext.setBounds(303, 12, 244, 23);
		all.add(alltext);
		alltext.setColumns(10);
		
		JButton button = new JButton("查询");
		button.setBounds(575, 11, 99, 23);
		all.add(button);
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
					allModel(select.findAllR(alltext.getText()));
			}
		});
		allModel(select.findAllR());
		JTable alltable = new JTable(allModel);

		JScrollPane scrollPane = new JScrollPane(alltable);
		scrollPane.setBounds(30, 97, 784, 411);
		all.add(scrollPane);
		JPanel live = new JPanel();
		live.setToolTipText("全部离店宾客信息查询");
		live.setLayout(null);
			
		tabbedPane.addTab("全部离店宾客信息查询",  live);
		
		JLabel lblNewLabels = new JLabel("姓名/房间号:");
		lblNewLabels.setBounds(140, 13, 179, 23);
		live.add(lblNewLabels);
		
		livetext = new JTextField();
		livetext.setBounds(303, 12, 244, 23);
		live.add(livetext);
		livetext.setColumns(10);
		
		JButton livebutton = new JButton("查询");
		livebutton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				setliveModel(select.findAllRLive(livetext.getText()));

			}
		});
		livebutton.setBounds(575, 11, 99, 23);
		live.add(livebutton);
		setliveModel(select.findAllRLive());
		JTable t1 =new JTable(liveModel);
		JScrollPane livePane = new JScrollPane(t1);
		livePane.setBounds(30, 97, 784, 411);
		live.add(livePane);
		JPanel start = new JPanel();
		start.setToolTipText("全部在店宾客信息查询");
		start.setLayout(null);
			
		tabbedPane.addTab("全部在店宾客信息查询",  start);
		
		JLabel lblNewLabel1 = new JLabel("姓名/房间号:");
		lblNewLabel1.setBounds(140, 13, 179, 23);
		start.add(lblNewLabel1);
		
		starttext = new JTextField();
		starttext.setBounds(303, 12, 244, 23);
		start.add(starttext);
		starttext.setColumns(10);
		
		JButton startbutton = new JButton("查询");
		startbutton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {

				setstartModel(select.findAllROn(starttext.getText()));

			}
		});
		startbutton.setBounds(575, 11, 99, 23);
		start.add(startbutton);
		setstartModel(select.findAllROn());
		JTable t12 =new JTable(startModel);
		JScrollPane startlPane = new JScrollPane(t12);
		startlPane.setBounds(30, 97, 784, 411);
		start.add(startlPane);

		all.setBackground(new Color(231,215,183));
		start.setBackground(new Color(231,215,183));
		live.setBackground(new Color(231,215,183));


		setVisible(true);
	}

	private void allModel(List<R> r) {
		Vector<Vector<String>> data = new Vector<>();

		for (R r1 : r) {
			Vector<String> v =new Vector<>();
			v.add(r1.getA());
			v.add(r1.getS());
			v.add(r1.getSs());
			v.add(r1.getSsss());
			v.add(r1.getSssss());
			v.add(r1.getSsss1s());
			data.add(v);
		}
		if (allModel == null){
			allModel = new DefaultTableModel(data,header);
		}
		allModel.setDataVector(data,header);
	}

	private void setstartModel(List<R> r) {
		Vector<Vector<String>> data = new Vector<>();

		for (R r1 : r) {
			Vector<String> v =new Vector<>();
			v.add(r1.getA());
			v.add(r1.getS());
			v.add(r1.getSs());
			v.add(r1.getSsss());
			v.add(r1.getSssss());
			v.add(r1.getSsss1s());
			data.add(v);
		}
		if (startModel == null){
			startModel = new DefaultTableModel(data,header);
		}
		startModel.setDataVector(data,header);
	}
	private void setliveModel(List<R> r) {
		Vector<Vector<String>> data = new Vector<>();

		for (R r1 : r) {
			Vector<String> v =new Vector<>();
			v.add(r1.getA());
			v.add(r1.getS());
			v.add(r1.getSs());
			v.add(r1.getSsss());
			v.add(r1.getSssss());
			v.add(r1.getSsss1s());
			data.add(v);
		}
		if (liveModel == null){
			liveModel = new DefaultTableModel(data,header);
		}
		liveModel.setDataVector(data,header);
	}
}
